//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "common\fn_actionSet.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_item","_actions","_action","_id","_index","_x","_i"];
DEFAULT_PARAM(_item,0,objNull);
DEFAULT_PARAM(_action,1,[]);
_actions = [];
TRACE_1("Item Type",typename _item);
if (typename _item == typename []) then {
	_actions = _item;
} else {
	_actions = [_item] call FFUNC(GetActions);
};
_id = [_action, TMF_HK_ACTION_ID,-1,THIS_FILE] call FFUNC(hashGet);
_index = count _actions;
if (_id >= 0 && count _actions > 0) then {
	for "_i" from 0 to ((count _actions) - 1) step 1 do {
		if (_id == ([(_actions select _i), TMF_HK_ACTION_ID,-1,THIS_FILE] call FFUNC(HashGet))) exitWith {_index = _i};
	};
};
TRACE_2("Found index",_index,(count _actions));
_actions set [_index, _action];
if (typename _item != typename []) then {
	[_item,_actions] call FFUNC(setActions);
};
TRACE_2("End",count _actions, _actions);
TMFPROFILERSTOP;
_actions;